package com.face.server.repository;

import com.face.server.entity.Admin;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import java.util.List;

/**
 * Created by ryan on 2018/1/25.
 */
public interface AdminRepository extends MongoRepository<Admin,String> {
    @Query(value = "{$and:[{auth.username:?0},{auth.password:?1}]}")
    Admin findByUsernameAndPassword(String username,String password);

    Page<Admin> findByNameRegexOrDormitoryNumListIs(Pageable pageable,String name,Integer num);

    Admin findByName(String name);

    Page<Admin> findByDormitoryNumListExists(Boolean b,Pageable pageable);

    List<Admin> findByNameRegex(String name);


    List<Admin> findByNameOrPhone(String searchKey);

    @Query("{isSuper:?0}")
    List<Admin> findBySuper(boolean s);

    @Query("{isSuper:false, name: {$regex: ?0, $options: 'i'}}")
    List<Admin> findByNameRegexAndNotSuper(String name);

    Page<Admin> findByNameRegex(String name,Pageable pageable);

    Admin findByIdentityAndPhone(String identity,String phone);

}
